package com.minivision.sdktestdemo.controler.ui.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.res.Resources;
import android.support.v4.content.IntentCompat;
import android.support.v4.widget.DrawerLayout;
import android.view.Gravity;
import android.view.View;
import android.widget.Switch;
import android.widget.TextView;

import com.minivision.sdktestdemo.R;
import com.minivision.sdktestdemo.service.MusicService;
import com.minivision.sdktestdemo.ui.ThemeChangeActivity;
import com.minivision.sdktestdemo.theme.utils.ThemeUtils;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/6/14.
 */
public class NavControler {
    private Activity mContext;

    public static final int REQUEST = 101;

    @Bind(R.id.drawer)
    DrawerLayout mDrawer;

    @Bind(R.id.switch_night)
    Switch mSwitch;

    @Bind(R.id.theme_name)
    TextView themeText;

    private boolean mStartFlag;

    public NavControler(Activity context) {
        mContext = context;
        ButterKnife.bind(this, context);
        mSwitch.setChecked(ThemeUtils.isDarkTheme());
        mDrawer.setDrawerListener(new DrawerLayout.DrawerListener() {
            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {

            }

            @Override
            public void onDrawerOpened(View drawerView) {
                themeText.setText(ThemeUtils.getThemeName());
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                if (mStartFlag) {
                    Intent intent = new Intent(mContext, ThemeChangeActivity.class);
                    mContext.startActivityForResult(intent, REQUEST);
                    mContext.overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
                }
                mStartFlag = false;
            }

            @Override
            public void onDrawerStateChanged(int newState) {

            }
        });
    }

    public void show() {
        mDrawer.openDrawer(Gravity.LEFT);
    }

    @OnClick(R.id.menu_skin)
    void onSetTheme() {
        mStartFlag = true;
        mDrawer.closeDrawers();
    }

    @OnClick({R.id.menu_night, R.id.switch_night})
    void onChangeDarkThme() {
        ThemeUtils.swithTheme(mContext);
        ThemeUtils.saveTheme(mContext);
        ThemeUtils.beginChange(mContext);
        mSwitch.setChecked(ThemeUtils.isDarkTheme());
    }

    @OnClick(R.id.stop_time)
    void onSetStopTime() {
        AlertDialog.Builder builder = null;
        AlertDialog s = null;
    }

    @OnClick(R.id.close_btn)
    void onCloseApplication() {
        mContext.stopService(new Intent(mContext, MusicService.class));
        mContext.finishAffinity();
    }
}
